﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace OmronProject
{
    public partial class Form1 : Form
    {
        readonly KeyboardHook _hook = new KeyboardHook();
        public Form1()
        {
            InitializeComponent();
            SetActiveDno();
            _hook.KeyPressed += HookKeyPressed;
            // register the control + alt + F12 combination as hot key.
            //ModifierKeys K = new ModifierKeys();
            _hook.RegisterHotKey(new ModifierKeys(), Keys.F1);
            _hook.RegisterHotKey(new ModifierKeys(), Keys.F2);
            _hook.RegisterHotKey(new ModifierKeys(), Keys.F3);
            _hook.RegisterHotKey(new ModifierKeys(), Keys.F4);
            _hook.RegisterHotKey(new ModifierKeys(), Keys.F5);
            _hook.RegisterHotKey(new ModifierKeys(), Keys.Up);
        }

        void HookKeyPressed(object sender, KeyPressedEventArgs e)
    {
        switch (e.Key)
        {
            case Keys.F1:
                SetActiveDno();
                break;
            case Keys.F2:
                SetActiveBok();
                break;
            case Keys.F3:
                SetActivePit();
                break;
            case Keys.F4:
                SetActiveAlg();
                break;
            case Keys.F5:
                SetActiveGp();
                break;
            case Keys.Up:
            //    TStopDno.Focus();
                break;
                
        }
    }

        

        private void OmronEdit3TextChanged(object sender, EventArgs e)
        {

        }
        private void setActiveColorPanel(Panel panel)
        {
            panel.BackColor = Color.Gray;
            foreach (Control i in panel.Controls)
            {
                if (i.GetType() == typeof(Label))
                    i.ForeColor = Color.Lime;
                if (i.GetType() == typeof(OmronEdit.OmronEdit))
                {
                    i.BackColor = Color.Khaki;
                    i.Enabled = true;
                }
            }
        }

        private void setPassiveColorPanel(Control panel)
        {
            panel.BackColor = SystemColors.Control;
            foreach (Control i in panel.Controls)
            {
                if (i.GetType() == typeof(Label))
                    i.ForeColor = Color.Black;
                if (i.GetType() == typeof(OmronEdit.OmronEdit))
                {
                    i.BackColor = Color.White;
                    i.Enabled = false;
                }
            }
        }
        private void SetActiveDno()
        {
            setActiveColorPanel(panel1);
            setPassiveColorPanel(panel2);
            setPassiveColorPanel(panel3);
            setPassiveColorPanel(panel4);
            setPassiveColorPanel(panel5);
            TTaskDno.Focus();
        }
        private void SetActiveBok()
        {
            setActiveColorPanel(panel2);
            setPassiveColorPanel(panel1);
            setPassiveColorPanel(panel3);
            setPassiveColorPanel(panel4);
            setPassiveColorPanel(panel5);
            omronEdit13.Focus();

        }

        private void SetActivePit()
        {
            setActiveColorPanel(panel3);
            setPassiveColorPanel(panel1);
            setPassiveColorPanel(panel2);
            setPassiveColorPanel(panel4);
            setPassiveColorPanel(panel5);
            omronEdit20.Focus();

        }
        private void SetActiveAlg()
        {
            setActiveColorPanel(panel4);
            setPassiveColorPanel(panel1);
            setPassiveColorPanel(panel3);
            setPassiveColorPanel(panel2);
            setPassiveColorPanel(panel5);
            omronEdit27.Focus();

        }

        private void SetActiveGp()
        {
            setActiveColorPanel(panel5);
            setPassiveColorPanel(panel1);
            setPassiveColorPanel(panel3);
            setPassiveColorPanel(panel2);
            setPassiveColorPanel(panel4);
            omronEdit27.Focus();

        }



        private void Button1Click(object sender, EventArgs e)
        {
            SetActiveDno();
        }

        private void Button2Click(object sender, EventArgs e)
        {
            SetActiveBok();
        }

        private void Form1Shown(object sender, EventArgs e)
        {
            TTaskDno.Focus();
            
        }



        
    }
}
